import axios from 'axios'

const state = {
	cattleList: [],
	cattleDetail: {
		market: {
			name: ''
		},
		yield:[]
	},
	// cattleDetail2:{}
}


const mutations = {
	// 更改牛人列表信息
	getCattleList(state, payload) {
		// console.log(payload.res)
		state.cattleList = payload.res
	},
	// 更改牛人详情详细
	getCattleDetail(state, payload) {
		// console.log(payload.res)
		state.cattleDetail = payload.res
	},
	getCattleDetail2(state, payload) {
		// console.log(payload.res)
		// console.log("23456234345")
		state.cattleDetail2 = payload.res
		console.log(state.cattleDetail2)
	},
	// 失败时清空牛人详细信息
	emptyCattleDetail(state) {
		state.cattleDetail = {
			market: {
				name: ''
			}
		}
	}
}

const actions = {
	// 获取牛人列表信息
	getCattleList({commit}) {
		axios.get('http://api.fxnn.net/market?page=1&page_size=20')
		.then(function(res) {
			// console.log(res.data.objs)
			commit({
				type: 'getCattleList',
				res: res.data.objs
			})
		})
	},
	// 获取牛人详情信息
	getCattleDetail({commit},param) {
		// console.log(param.id);
		axios.get("http://api.fxnn.net/marketdetail?id="+param.id+"&random="+Math.random())
		.then(function (res) {
			commit({
				type: 'getCattleDetail',
				res: res.data.data
			})
		})
		.catch(function (err) {
			commit({type:'emptyCattleDetail'})
		})

		axios.get("fxnnapi/api/market/detail/"+param.id) 
		.then(function (res) {
			commit({
				type: 'getCattleDetail2',
				res: res.data
			})
		})
		.catch(function (err) {
		})


	}
}

export default {
	state,
	mutations,
	actions
}